<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>百媚后花园</title>
    <script src="../base/js/jquery-1.10.2.js"></script>
    <script src="../base/js/XT.js"></script>
    <link rel="stylesheet" href="../base/css/weui.css">
    <style>
        body {
            background-color: #fbf9fe;
        }
        .page_title {
            text-align: center;
            font-size: 34px;
            color: #3cc51f;
            font-weight: 400;
            margin: 20px 15% 0;
        }

        .m{
            margin-top: 40px;
        }
    </style>
</head>
<body ontouchstart="">
    <h1 class="page_title">Back Garden (JS)</h1>
    <section class="m">
        <div class="weui_cells_title">获取用户信息</div>
        <div class="weui_btn_area">
            <a href="javascript:;" class="weui_btn weui_btn_primary" data-action="getUserInfo">获取用户信息</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">设置环境API参数</div>
        <div class="weui_btn_area">
            <!--<a href="javascript:;" class="weui_btn weui_btn_primary" data-action="changeBaseUrl" data-only="{api:'https://api-dev.chinaqljf.com',chat:'https://chat-dev.chinaqljf.com',pay:'https://pay-dev.chinaqljf.com',h5:'https://h5-dev.chinaqljf.com',fun:'https://fun-dev.chinaqljf.com',game:'https://game-token-dev.chinaqljf.com',shop:'https://bmshop-dev.chinaqljf.com'}">设置为dev环境</a>-->
            <a href="javascript:;" class="weui_btn weui_btn_primary" data-action="changeBaseUrl" data-only="{api:'https://api-t.chinaqljf.com',chat:'https://chat-t.chinaqljf.com',pay:'https://pay-t.chinaqljf.com',h5:'https://h5-t.chinaqljf.com',fun:'https://fun-t.chinaqljf.com',game:'https://game-token-t.chinaqljf.com',shop:'https://bmshop-t.chinaqljf.com',panelShop:'https://bmshop-h5-t.chinaqljf.com'}">设置为test环境</a>
            <!--<a href="javascript:;" class="weui_btn weui_btn_primary" data-action="changeBaseUrl" data-only="{api:'https://api-a.chinaqljf.com',chat:'https://chat-a.chinaqljf.com',pay:'https://pay-a.chinaqljf.com',h5:'https://h5-a.chinaqljf.com',fun:'https://fun-a.chinaqljf.com',game:'https://game-token-a.chinaqljf.com',shop:'https://bmshop-a.chinaqljf.com'}">设置为alpha环境</a>-->
            <a href="javascript:;" class="weui_btn weui_btn_primary" data-action="changeBaseUrl" data-only="{api:'https://api.chinaqljf.com',chat:'https://chat.chinaqljf.com',pay:'https://pay.chinaqljf.com',h5:'https://h5.chinaqljf.com',fun:'https://fun.chinaqljf.com',game:'https://game-token.chinaqljf.com',shop:'https://ashop.baimeitv.com',panelShop:'https://ashop-h5.baimeitv.com'}">设置为prod环境</a>
        </div>
        <br>
        <div class="weui_cells_tips">或者你可以选择自定义</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*api</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入api域名" data-target="value" data-key="api">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*chat</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入chat域名" data-target="value" data-key="chat">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*pay</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入pay域名" data-target="value" data-key="pay">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*h5</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入h5域名" data-target="value" data-key="h5">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*fun</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入fun域名" data-target="value" data-key="fun">
                </div>
            </div>
        </div>
        <div class="weui_cells_tips">带 * 为必填项</div>
        <div class="weui_btn_area">
            <a href="javascript:;" class="weui_btn weui_btn_primary" data-action="changeBaseUrl">设置为自定义环境</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">分享</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*id</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入分享内容id" data-target="value" data-key="id">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*类型</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入分享内容类型" data-target="value" data-key="type">
                </div>
            </div>
        </div>
        <div class="weui_cells_tips">带 * 为必填项</div>
        <div class="weui_btn_area">
            <a class="weui_btn weui_btn_primary" href="javascript:" data-action="share">分享</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">设置分享按钮</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*id</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入分享id" data-target="value" data-key="id">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*类型</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入分享按钮类型" data-target="value" data-key="type">
                </div>
            </div>
        </div>
        <div class="weui_cells_tips">带 * 为必填项</div>
        <div class="weui_btn_area">
            <a class="weui_btn weui_btn_primary" href="javascript:" data-action="setShareInfo">设置分享按钮</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">获取设备信息</div>
        <div class="weui_btn_area">
            <a href="javascript:;" class="weui_btn weui_btn_primary" data-action="getDeviceInfo">获取设备信息</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">获取设备ID</div>
        <div class="weui_btn_area">
            <a href="javascript:;" class="weui_btn weui_btn_primary" data-action="getDeviceId">获取设备ID</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">关闭当前页面</div>
        <div class="weui_btn_area">
            <a href="javascript:;" class="weui_btn weui_btn_primary" data-action="closeView">关闭当前页面</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">获取Agent信息</div>
        <div class="weui_btn_area">
            <a href="javascript:;" class="weui_btn weui_btn_primary" data-action="getUserAgent">获取Agent信息</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">使用系统浏览器打开</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*url</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入url" data-target="value" data-key="url">
                </div>
            </div>
        </div>
        <div class="weui_cells_tips">带 * 为必填项</div>
        <div class="weui_btn_area">
            <a class="weui_btn weui_btn_primary" href="javascript:" data-action="jumpPage">打开浏览器</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">是否支持某方法</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*方法名</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入方法名" data-target="value" data-key="method">
                </div>
            </div>
        </div>
        <div class="weui_cells_tips">带 * 为必填项</div>
        <div class="weui_btn_area">
            <a class="weui_btn weui_btn_primary" href="javascript:" data-action="support">测试支持</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">复制到剪贴板</div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*内容</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入需要复制的内容" data-target="value" data-key="content">
                </div>
            </div>
        </div>
        <div class="weui_cells_tips">带 * 为必填项</div>
        <div class="weui_btn_area">
            <a class="weui_btn weui_btn_primary" href="javascript:" data-action="copyToClipboard">测试支持</a>
        </div>
    </section>

    <section class="m">
        <div class="weui_cells_title">测试被动触发的协议</div>
        <div class="weui_btn_area">
            <a class="weui_btn weui_btn_primary" href="bmlive://bmlive/uploadtxpic?text=%23%E4%B8%8B%E4%B8%80%E7%AB%99%E5%A5%B3%E5%84%BF%E5%9B%BD%23">用发布图文来测试onActionCallback</a>
        </div>
    </section>

    <script>
        $(function () {
            $('.m').each(function  () {
                var $this = $(this);
                $this.find('[data-action]').on('click', function(event) {
                    event.preventDefault();
                    var obj = {};
                    var url = $(this).data('action');
                    var only = $(this).data('only');

                    if(!only) {
                        $this.find('[data-target]').each(function (num) {
                            var item = $(this);
                            var value = '';
                            var key = item.data('key');

                            if(!key) return;

                            switch(item.data('target')) {

                                case 'value':
                                    value = encodeURIComponent(item.val());
                                    break;
                            }

                            if(value !== '') {
                                obj[key] = value;
                            }
                        })
                    }else {
                        try{
                            var o = eval("("+only+")");
                            typeof o == 'object' && (obj = o);
                            for(var key in obj) {
                                var val = obj[key];
                                obj[key] = encodeURIComponent(val);
                            }
                        }
                        catch (e) {
                        }
                    }

                    console.log(JSON.stringify(obj))
                    XT.bridge.call(url,obj,function (res) {
                        alert(JSON.stringify(res))
                    })
                });
            })

            XT.bridge.on('onActionCallback',function (res) {
                alert('onActionCallback is working ! And arguments is '+JSON.stringify(res));
            })
        })
    </script>
</body>
</html>
